//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
//==========================================================================
// Copyright (c) 2000-2004,  Elastos, Inc.  All Rights Reserved.
//**author:hanxu
//**y/m/d:2005/5/26
//==========================================================================

#ifndef __ELASTOS_VGA_H__
#define __ELASTOS_VGA_H__

#define VGATXTMODE          0
#define VGAGDIMODE          1

class Video : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ UInt32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ UInt32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 nControlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI WritePixel(
        /* [in] */ UInt64 u64Offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ UInt32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    virtual void Dispose() {}

    Video()
    {
        m_uScrWidth = 800;
        m_uScrHeight = 600;
        m_uScrBpp = 16;
        m_uScrHz = 75;

        m_uCursorLocation = 0;
        m_uTxtCursorLocation = 0;

        m_uCharWidth = 8;
        m_uCharHeight = 16;
        m_u16DrawColor = 0xffff;
        m_uScrTxtCols = m_uScrWidth / m_uCharWidth;
        m_uScrTxtRows = m_uScrHeight / m_uCharHeight;
        m_bGDIMODE = false;
    }

private:

public:

    uint32_t            m_uCursorLocation;
    uint32_t            m_uTxtCursorLocation;

    // screen initialise parameter:
    uint32_t            m_uScrWidth;
    uint32_t            m_uScrHeight;
    uint32_t            m_uScrBpp;
    uint32_t            m_uScrHz;

    // for text mode
    uint32_t            m_uScrTxtCols;
    uint32_t            m_uScrTxtRows;
    uint32_t            m_uCharWidth;
    uint32_t            m_uCharHeight;
    uint16_t            m_u16DrawColor;
//    uint8_t             m_u8TextFont;
    
    // mapped vga virtual address for user-mode calls
    uint32_t         m_uVirtAddr;

    // vga frame buffer physical base address
    uint32_t         m_uFrameBufBase;
    uint32_t         m_uIoBufBase;    // vga IO buffer physical base address

    uint32_t         m_uVgaMemSize; // probed vga memory size
    bool             m_bGDIMODE;
};

EXTERN IDeviceDriver * CDECL CreateVGA(uint_t uDeviceNo, void *pvParameter);
EXTERN void DrawChar(char c, uint32_t buffer, uint16_t draw_color);

#endif // __ELASTOS_VGA_H__
